package me.zhengjie.exercise.repository;

import me.zhengjie.exercise.entity.ExerciseUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

/**
 * @author wanggang
 */
public interface ExerciseUserRepository extends JpaRepository<ExerciseUser, Long>, JpaSpecificationExecutor<ExerciseUser> {

    /**
     * 删除
     *
     * @param ids /
     */
    void deleteByIdIn(Set<Long> ids);

    /**
     * 查询
     *
     * @param ids /
     * @return /
     */
    List<ExerciseUser> findByIdIn(Set<Long> ids);

    /**
     * jpa例子 - 通过方法名查询
     */
    List<ExerciseUser> findByUserNameAndSex(String userName, String sex);

    /**
     * jpa例子 - 通过方法名查询
     */
    List<ExerciseUser> findBySex(String sex);

    /**
     * jpa例子 - native sql
     */
    @Query(value = "SELECT * from exercise_user where sex = ?1 ", nativeQuery = true)
    List<ExerciseUser> searchUsersBySex(String sex);

    /**
     * jpa例子 - jpql
     */
    @Query(value = "SELECT o from ExerciseUser o where o.sex = ?1 ")
    List<ExerciseUser> searchUsersBySex2(String sex);
}
